<template>
  <el-container class="home-container">
    <el-header>
      <div class="login_name">电商管理后台</div>
      <el-button @click="loginout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="togglemenus ? '64px' : '200px'">
        <div class="togglecopss" @click="togglemenu">|||</div>
        <el-menu
          background-color="#0f0f00"
          text-color="#fff"
          active-text-color="#0FA9F8"
          unique-opened
          :collapse="togglemenus"
          :collapse-transition="false"
          router
          :default-active="activePath"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <template slot="title">
              <i :class="menuicon[item.id]"></i>
              <span>{{ item.autName }}</span>
            </template>

            <el-menu-item
              :index="'/' + subitem.path"
              v-for="subitem in item.children"
              :key="subitem.id"
              @click="activeMenu('/' + subitem.path)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ subitem.autName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu></el-aside
      >
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      togglemenus: false,
      activePath: '',
      menulist: [
        {
          id: 1,
          autName: '用户管理',
          path: null,
          children: [
            {
              id: 81,
              autName: '用户列表',
              path: 'users',
              children: [],
            },
          ],
        },
        {
          id: 2,
          autName: '权限管理',
          path: null,
          children: [
            {
              id: 102,
              autName: '权限列表',
              path: 'roles',
              children: [],
            },
            {
              id: 103,
              autName: '角色列表',
              path: 'rights',
              children: [],
            },
          ],
        },
        {
          id: 3,
          autName: '商品管理',
          path: null,
          children: [
            {
              id: 43,
              autName: '商品列表',
              path: 'goodslist',
              children: [],
            },
            {
              id: 53,
              autName: '分类参数',
              path: 'classification',
              children: [],
            },
            {
              id: 63,
              autName: '商品分类',
              path: 'goods',
              children: [],
            },
          ],
        },
        {
          id: 5,
          autName: '订单管理',
          path: null,
          children: [
            {
              id: 151,
              autName: '订单列表',
              path: 'orderlist',
              children: [],
            },
          ],
        },
        {
          id: 6,
          autName: '数据统计',
          path: null,
          children: [
            {
              id: 106,
              autName: '数据列表',
              path: 'datalist',
              children: [],
            },
          ],
        },
      ],
      menuicon: {
        1: 'iconfont icon-yonghu',
        2: 'iconfont icon-quanxianguanli',
        3: 'iconfont icon-shangpin',
        5: 'iconfont icon-dingdanguanli',
        6: 'iconfont icon-shujutongji',
      },
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    loginout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    togglemenu() {
      this.togglemenus = !this.togglemenus
    },
    activeMenu(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
  },
}
</script>
<style lang="less" scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #0f0f00;
  display: flex;
  justify-content: space-between;
  .login_name {
    display: flex;
    align-items: center;
    font-size: 20px;
    color: #fff;
  }
}
.el-aside {
  background-color: #0f0f00;
}
.el-main {
  background-color: rgb(241, 245, 248);
}
.el-menu {
  border: 0;
}
.iconfont {
  padding-right: 10px;
}
.togglecopss {
  background-color: #8c8e8f;
  font-size: 10px;
  color: #fff;
  line-height: 24px;
  letter-spacing: 1em;
  text-align: center;
  cursor: pointer;
}
</style>